<?php

App::uses('AppModel', 'Model');

/**
 * ProjectDetail Model
 *
 * @property Project $Project
 */
class ProjectDetail extends AppModel {

    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array(
        'language' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'title' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter title.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'project_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'price' => array(
            'numeric' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter price.',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed

    /**
     * belongsTo associations
     *
     * @var array
     */
    public $belongsTo = array(
        'Project' => array(
            'className' => 'Project',
            'foreignKey' => 'project_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    
    public function getToMenu($limit, $lang = NULL){
        if ($lang == NULL) {
            $lang = ENG_LANG;
        }

        $data = $this->Find('all', array(
            'fields'=>array(
              'ProjectDetail.title','ProjectDetail.project_id'  
            ),
            'conditions' => array(
                'ProjectDetail.language' => $lang,
            ),            
            'limit' => $limit,
            'recursive' => -1
        ));
        return $data;
    } 

}
